import { defineStore } from 'pinia'
import { ref } from 'vue'
import { TSystemTitle } from '../../Types/system'
import { getSystemTitleService } from '../../api/system/title'

// 命名规范：use+名称+Store   第一个参数为唯一标识
export const useSystemStore = defineStore(
	'sms-system',
	() => {
		// 系统标题
		const systemTitle = ref<TSystemTitle>()

		// 获取标题
		const getSystemTitle = async () => {
			const res = await getSystemTitleService()
			systemTitle.value = res.data.data
		}

		// 修改标题
		const reviseSystemTitle = (newData: TSystemTitle) => {
			console.log('设置系统标题:', newData)
			systemTitle.value = newData
		}

		// 清除标题
		const removeSystemTitle = () => {
			systemTitle.value = undefined
		}

		// 暴露
		return {
			systemTitle,
			getSystemTitle,
			reviseSystemTitle,
			removeSystemTitle
		}
	},
	{
		persist: true // 开启持久化
	}
)
